package com.qfedu.edu.bo;

import com.qfedu.edu.pojo.User;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * @author xiaobobo
 * @title: SecurityUser
 * @projectName cd-fy-2401-third-project-parent
 * @description: TODO
 * @date 2024/9/13  14:14
 */
@Data
public class SecurityUser implements UserDetails {

    //账户对象
    private Account account;

    //角色和权限的集合
    private List<String> roleAndPerms;

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        //申明一个存储权限和角色的集合对象
        List<GrantedAuthority> grantedAuthorities=new ArrayList<>();
        for (int i = 0; i <roleAndPerms.size() ; i++) {
            //放到我们的集合中去
            grantedAuthorities.add(new SimpleGrantedAuthority(roleAndPerms.get(i)));
        }
        return grantedAuthorities;
    }

    @Override
    public String getPassword() {
        return account.getPassword();
    }

    @Override
    public String getUsername() {
        return account.getUsername();
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }
}
